package com.example.shiro.shiro.aspect;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


/**
 * @author chong
 * @create 2020/3/11
 * Desc:
 */

@Configuration
public class MyHandlerInterceptorConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        /**
         * 这里的addPathPatterns("/**")为配置需要拦截的方法“/**”代表所有，
         * 而后excludePathPatterns("/user/toLogin")等方法为排除哪些方法不进行      拦截
         */
        registry.addInterceptor(getAccessInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/shiro/login")
                .excludePathPatterns("/login")
                .excludePathPatterns("/loginIn")
                .excludePathPatterns("/register");
        super.addInterceptors(registry);
    }

    @Bean
    public MyHandlerInterceptor getAccessInterceptor(){
        System.out.println("注入了AccessInterceptor");
        return new MyHandlerInterceptor();
    }
}


